分页类的定义
"个记录", "prev"=>"上一页", "next"=>"下一页", "first"=>"首 页", "last"=>"尾 页"); private $linkNum=8;//分页相关按钮数目设置 /* * $total * $listRows */ public function __construct($totalCount, $pageSize=10, $pageURI=""){ $this->totalCount=$totalCount; $this->pageSize=$pageSize; $this->uri=$this->getUri($pageURI); $this->pageIndex=!empty($_GET["pageIndex"]) ? $_GET["pageIndex"] : 1; $this->totalPage=ceil($this->totalCount/$this->pageSize); $this->limit=$this->setLimit(); } private function setLimit(){ return "Limit ".($this->pageIndex-1)*$this->pageSize.", {$this->pageSize}"; } private function getUri($pageURI){ $url=$_SERVER["REQUEST_URI"].(strpos($_SERVER["REQUEST_URI"], '?')?'':"?").$pageURI; $parse=parse_url($url); if(isset($parse["query"])){ parse_str($parse['query'],$params); unset($params["pageIndex"]); $url=$parse['path'].'?'.http_build_query($params); } return $url; } function __get($args){ if($args=="limit") return $this->limit; else return null; } private function start(){ if($this->totalCount==0) return 0; else return ($this->pageIndex-1)*$this->pageSize+1; } private function end(){ return min($this->pageIndex*$this->pageSize,$this->totalCount); } private function first(){ $html = ""; if($this->pageIndex==1) $html.=''; else $html.=" {$this->config["first"]} "; return $html; } private function prev(){ $html = ""; if($this->pageIndex==1) $html.=''; else $html.=" {$this->config["prev"]} "; return $html; } private function pageList(){ $linkPage=""; $inum=floor($this->linkNum/2); for($i=$inum; $i>=1; $i--){ $pageIndex=$this->pageIndex-$i; if($pageIndex<1) continue; $linkPage.=" {$pageIndex} "; } $linkPage.=" {$this->pageIndex} "; for($i=1; $i<=$inum; $i++){ $pageIndex=$this->pageIndex+$i; if($pageIndex<=$this->totalPage) $linkPage.=" {$pageIndex} "; else break; } return $linkPage; } private function next(){ $html = ""; if($this->pageIndex==$this->totalPage) $html.=''; else $html.=" {$this->config["next"]} "; return $html; } private function last(){ $html = ""; if($this->pageIndex==$this->totalPage) $html.=''; else $html.=" {$this->config["last"]} "; return $html; } private function goPage(){ return ' '.$this->totalPage.')?'.$this->totalPage.':this.value;location=\''.$this->uri.'&pageIndex=\'+pageIndex+\'\'}" value="'.$this->pageIndex.'" style="width:25px">'.$this->totalPage.')?'.$this->totalPage.':this.previousSibling.value;location=\''.$this->uri.'&pageIndex=\'+pageIndex+\'\'"> '; } function fpage($display=array(0,1,2,3,4,5,6,7,8)){ $html[0]=" 共有{$this->totalCount}{$this->config["header"]} "; $html[1]=" 每页显示".($this->end()-$this->start()+1)."条,本页{$this->start()}-{$this->end()}条 "; $html[2]=" {$this->pageIndex}/{$this->totalPage}页 "; $html[3]=$this->first(); $html[4]=$this->prev(); $html[5]=$this->pageList(); $html[6]=$this->next(); $html[7]=$this->last(); $html[8]=$this->goPage(); $fpage=''; foreach($display as $index){ $fpage.=$html[$index]; } return $fpage; }}
在控制器中使用分页类
display(); } /**分页留言数据*/ public function listgb() { $pageIndex = isset($_GET['pageIndex']) ? $_GET['pageIndex'] : 1; $pageSize = isset($_GET['pageSize']) ? $_GET['pageSize'] : 10; $like = isset($_GET['like']) ? $_GET['like'] : null; $gm = new GbmgrModel(); //获得符合条件的总记录数 $totalCount = $gm->count($like); //获得分页数据 $list = $gm->list($pageIndex, $pageSize, $like); $url = "index.php?g=admin&c=page&a=listgb&pageIndex={pageIndex}"; $myPage=null; if ($totalCount > $pageSize) {//总记录数大于每页显示数,显示分页 $myPage = new \core\MyPage($totalCount, $pageSize, $pageIndex, $url, 2); } $this->assign('list',$list); $this->assign("myPage",$myPage); $this->display(); }}
视图定义
Page类分页 data['myPage']->outPages();?>
data['list'] as $value){ echo " 编号 姓名 邮箱 电话 留言 "." "; } ?>".$value['id']. " "."".$value['uname']. " "."".$value['uemail']. " "."".$value['uphone']. " "."".$value['umessage']. " "."